<template>
  <el-dialog title="编辑" :visible="dialogVisible" :before-close="closeDialog">
    <el-form :model="formData">
      <el-form-item label="标题">
        <el-input v-model="formData.title"></el-input>
      </el-form-item>
      <el-form-item label="图标class">
        <el-input v-model="formData.icon"></el-input>
      </el-form-item>
      <el-form-item label="是否隐藏">
        <el-switch v-model="formData.hidden"> </el-switch>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="sureDialog">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: {
    // 是否打开dialog
    dialogVisible: {
      type: Boolean,
      default: false
    },
    // 菜单信息
    menuInfo: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    dialogVisible: {
      immediate: true,
      handler(val) {
        if (!val) return;
        this.formData = JSON.parse(JSON.stringify(this.menuInfo));
      }
    }
  },
  data() {
    return {
      formData: {}
    };
  },
  methods: {
    // 关闭弹窗
    closeDialog() {
      this.$emit("closeDialog");
    },
    // 提交表单
    sureDialog() {
      this.$emit("sureDialog", this.formData);
    }
  }
};
</script>

<style lang="scss" scoped></style>
